<div class="top">
  <h1><?php echo $heading_title; ?></h1>
</div>
<div class="middle"><b><?php echo $text_critea; ?></b>
  <div id="content_search" style="background: #F6F9FF; border: 1px solid #cdddff; padding: 10px; margin-top: 3px; margin-bottom: 10px;moz-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;">
    <table cellpadding=10 cellspacing=10>
      <tr>
        <td><?php echo $entry_search; ?></td>
        <td><?php if ($keyword) { ?>
          <input type="text"  name="keyword" value="<?php echo $keyword; ?>" id="keyword" />
          <?php } else { ?>
          <input type="text" onFocus="this.value=''" name="keyword" value="<?php echo $text_keywords; ?>" id="keyword" />
          <?php } ?></td>
		 
		 
		<!-- Modifi by Hai Dang 20/12 -->
		<td>
		<select name="filter_category_id">
			<option value="999"><?php echo $text_category; ?></option>
			<?php foreach ($categories as $category_1) { ?>
				<?php if ($category_1['category_id'] == $filter_category_id) { ?>
				<option value="<?php echo $category_1['category_id']; ?>" selected="selected"><?php echo $category_1['name']; ?></option>
				<?php } else { ?>
				<option value="<?php echo $category_1['category_id']; ?>"><?php echo $category_1['name']; ?></option>
				<?php } ?>
				<?php foreach ($category_1['children'] as $category_2) { ?>
					<?php if ($category_2['category_id'] == $filter_category_id) { ?>
					<option value="<?php echo $category_2['category_id']; ?>" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $category_2['name']; ?></option>
					<?php } else { ?>
					<option value="<?php echo $category_2['category_id']; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $category_2['name']; ?></option>
					<?php } ?>
				<?php } ?>
			<?php } ?>
		</select>
		</td>
		<!-- End -->
      </tr>

      <tr>
        <td colspan="2"><?php if ($description) { ?>
          <input type="checkbox" name="description" id="description" checked="checked" />
          <?php } else { ?>
          <input type="checkbox" name="description" id="description" />
          <?php } ?>
          <?php echo $entry_description; ?></td>

      </tr>
    </table>
  </div>
  <div class="buttons">
    <table>
        <td align="right"><a onclick="contentSearch();" class="button"><span><?php echo $button_search; ?></span></a></td>
      <tr>
      </tr>
    </table>
  </div>

  <div class="heading">Kết quả tìm kiếm</div>
  <?php if (isset($products)) { ?>
  <div class="sort">
    <div class="div1">
      <select name="sort" onchange="location=this.value">
        <?php foreach ($sorts as $sorts) { ?>
        <?php if (($sort . '-' . $order) == $sorts['value']) { ?>
        <option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option>
        <?php } else { ?>
        <option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option>
        <?php } ?>
        <?php } ?>
      </select>
    </div>

    <div class="div2"><?php echo $text_sort; ?></div>
  </div>
  <table class="catalog">
  	<tr style="background-color: #c8ebff;height: 25px;">
  		<td width="15%">
  		</td>
  		<td width="45%">
  		 	Tên sản phẩm
  		</td>
  		<td width="25%">
  			Giá
  		</td>
  		<td width="20%">
  			Phạm vi bán
  		</td>
  	</tr>

  <?php for ($i = 0; $i < sizeof($products); $i++) { ?>
  	<tr>

  		<td width="15%">
  			<a href="<?php echo $products[$i]['href']; ?>">
  				<img style="padding: 10px;" width="120px" src="<?php echo $products[$i]['thumb']; ?>" title="<?php echo $products[$i]['name']; ?>"/>
  			</a>
  		</td>
  		<td width="35%">
  			<h1>
  				<a style="margin-top: 10px;" href="<?php echo $products[$i]['href']; ?>"><?php echo $products[$i]['name']; ?></a>
  			</h1>
  			<h1 style="font-size: 11px; padding-top: 10px;">
  			Đăng bởi:
  			<?php if(isset($products[$i]['shop_name'])) {?>
  				<a href="<?php echo $products[$i]['href_shop'] ?>" >
  						<?php echo $products[$i]['shop_name'] ?>
  					</a>
  			<?php } ?>
  			</h1>
  			<h1 style="padding-top: 15px;">
  				<span style="color: #999; font-size: 11px;">
  					Ngày đăng:<?php echo $products[$i]['date_added']; ?> |
  				</span>
  				<span style="color: #999; font-size: 11px;">
  					Xem:<?php echo $products[$i]['viewed']; ?> |
  				</span>
  				<span style="color: #999; font-size: 11px;">
  					Comments:<?php echo $products[$i]['rating']; ?>
  				</span>
  			</h1>
  		</td>
  		<td width="15%">
	  		<?php if ($display_price) { ?>
	        		<?php if (!$products[$i]['special']) { ?>
	        			<span style="color: #900; font-weight: bold;"><?php echo $products[$i]['price']; ?>
	        			</span>
	        		<?php } else { ?>
	        			<span style="color: #900; font-weight: bold; text-decoration: line-through;">
	        			<?php echo $products[$i]['price']; ?>
	        			</span>
	        			<span style="color: #F00;">
	        				<?php echo $products[$i]['special']; ?>
	        			</span>
	        	<?php } ?>
	        <?php } ?>
  		</td>
  		<td width="20%">
  			<span style="font-size: 12px;">
  				<?php echo $products[$i]['zone']; ?>
  			</span>
  		</td>
  	</tr>
  <?php } ?>
  </table>
  <?php if ($products) { ?>
  <div class="pagination"><?php echo $pagination; ?></div>
  <?php } ?>
</div>
<?php } else { ?>
<div style="clear: both; height:23px;background-color:#F6F9FF;">
	Không tìm thấy sản phẩm nào.
</div>
<?php } ?>
<style type="text/css">
	.catalog {
		border:1px solid #77b7ff;
	}
	.catalog td {
		border-bottom:1px solid #77b7ff;
		border-left: 1px solid #abdcff;
		border-right: 1px solid #abdcff;
		text-align: left;
		margin-top: 2px;
		padding-left: 10px;
	}
	.catalog tr td h1 {
		color: blue;
		margin-top: 1px;
		font-weight: lighter;
	}

	.catalog tr td h1 a {
		color:blue;
		margin-top: 1px;
		font-weight: lighter;
		font-size:11;
		text-decoration: none;
	}
</style>
<script type="text/javascript">
$('#content_search input').keydown(function(e) {
	if (e.keyCode == 13) {
		contentSearch();
	}
});
function contentSearch() {
	url = 'index.php?route=product/search';
	var keyword = $('#keyword').attr('value');
	
	if (keyword) {
		url += '&keyword=' + encodeURIComponent(keyword);
	}
	if ($('#description').attr('checked')) {
		url += '&description=1';
	}
	//Edit by Hai Dang
	var filter_category_id = $('#content select[name=\'filter_category_id\']').attr('value');
	if (filter_category_id) {
		url += '&filter_category_id=' + encodeURIComponent(filter_category_id);
	}
	//End
	location = url;
}
</script>
